package io.gitee.zkool.barcodegun.pc.utils;

import java.awt.*;
import java.awt.event.KeyEvent;

/**
 * @author zhaokk
 * @since 2024/2/17
 */
public class KeyboardInputUtil {

    public static void stringInput(String inputText) throws AWTException {
        // 创建Robot对象
        Robot robot = new Robot();
        robot.delay(100);
        // 模拟输入的字符串
        for (char c : inputText.toCharArray()) {
            System.out.println(c);
            if(c == ':'){
                robot.keyPress(KeyEvent.VK_SHIFT);
                robot.keyPress(KeyEvent.VK_SEMICOLON);
                robot.keyRelease(KeyEvent.VK_SEMICOLON);
                robot.keyRelease(KeyEvent.VK_SHIFT);
                continue;
            }
            int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);

        }
    }

    public static void main(String[] args) {
      /*  System.out.println((int)';');
        try {
            KeyboardInputUtil.stringInput("123");
        } catch (AWTException e) {
            e.printStackTrace();
        }*/
        System.out.println(KeyEvent.getExtendedKeyCodeForChar('?'));
        System.out.println(KeyEvent.getExtendedKeyCodeForChar('？'));
        System.out.println((int)'?');
        System.out.println((int)'？');
    }

}
